
#ifndef __RBFFUNCTION_H__
#define __RBFFUNCTION_H__

#include "../typedefs.h"
#include "constraints.h"

#include <cpplapack.h>
typedef CPPL::dgematrix    MatrixCPPL;     ///< A CPPLapack matrix
   
using namespace std;

class RBFfunction {
   
public:
   
   RBFfunction();
   ~RBFfunction();
   
   void clear();
   void setting(const Constraints *c);
   
   /// Evaluates the RBF function on a point
   Point3 evalf(const Point3 &p);
   Point3 evalf(const Vector3 &p);
   
   /// Computes the RBF-weights
   void compute_lambdas(const Constraints *c);
   
protected:
   /// Computes the inverse of the RBF-matrix
   void compute_iM();
   
   /// The basis function
   inline Number phi(const Vector3& v);
   
   /// Evaluates a point in a term of the sum
   Number polynomial(const Point3& p, unsigned int i);
   
   /// Define the polynomial degree
   void polynomialDegree(unsigned int i);
   
public:
   Constraints     constraints;
   
protected:
   
   MatrixCPPL           iM;
   MatrixCPPL           lambdas;
   
   unsigned             n;           /// control points number
   unsigned             npolyterms;  /// number of polynomial terms
};

#endif
